package edu.cmu.abi.track;

import java.util.HashMap;

public abstract class Statistics {
	public double[] values;
	public HashMap<String, Double> statistics = new HashMap<String, Double>();
	
	public Statistics(double[] array){
		this.values=array;
		calculateStatistics();
	}
	
	public int getNumOfValues(){
		return this.values.length;
	}
	
	public void calculateStatistics() {
		int n = 0;
		double sum = 0;
		double sum_sqr=0;
		for(double x:this.values){
			n=n+1;
			sum+=x;
			sum_sqr=sum_sqr+x*x;
		}
		double mean=sum/n;
		double variance  = (sum_sqr-(sum*mean))/n;
		
		statistics.put("sum", sum);
		statistics.put("mean", mean);
		statistics.put("var", variance);
	}
}
